/***************************************************************************
 *  Filename: i2chandler.h
 *  Class: I2CHandler
 *  
 *  Copyright 2012  Jacco van der Spek
 *  <jaccovdspek@gmail.com>
 *
 *  Copyright 2012  Mario Henrique Voorsluys
 *  <forcaeluz@gmail.com>
 *  
 ****************************************************************************/

/*
 *
 * This file is part of %ProjectName%.
 *
 *    %ProjectName% is free software: you can redistribute it and/or modify
 *    it under the terms of the GNU General Public License as published by
 *    the Free Software Foundation, either version 3 of the License, or
 *    (at your option) any later version.
 *
 *    %ProjectName% is distributed in the hope that it will be useful,
 *    but WITHOUT ANY WARRANTY; without even the implied warranty of
 *    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *    GNU General Public License for more details.
 *
 *    You should have received a copy of the GNU General Public License
 *    along with %ProjectName%.  If not, see <http://www.gnu.org/licenses/>.
 */

#ifndef I2CHANDLER_H
#define I2CHANDLER_H

#include <QObject>
#include <ftdi.h>

class I2CHandler: public QObject {
    Q_OBJECT
public:
    explicit I2CHandler();
    QByteArray readI2c(char device_adr, char reg_adr, int size);
    void writeI2c(char device_ard, char reg_adr, char* data, int size);
    void initialize();
    void deInit();

private:
    int sendI2CByte(unsigned char byte);
    int sendFTDIData();
    bool startI2C();
    bool stopI2C();
    unsigned char outputBuffer[256];
    unsigned char inputBuffer[256];
    int bytesToSend;
    int bytesSent;
    int bytesRead;
    ftdi_context context;


};

#endif // I2CHANDLER_H
